import {
  addPhase,
  modifyPhase,
  deletePhase,
  finish,
  findPhaseTeam,

} from '../services/phase';

export default {
  namespace: 'phase',

  state: {
    mingdanList: [],
  },

  effects: {
    *addPhase({ payload }, { select, call, put }) {
      const response = yield call(addPhase, payload);
      if(response){
        yield put({
          type: 'gameProject/findGameProject',
        });
      }
    },
    *modifyPhase({ payload, callback }, { select, call, put }) {
      const response = yield call(modifyPhase, payload);
      if(response){
        yield put({
          type: 'gameProject/findGameProject',
        });
        if(callback) callback();
      }
    },
    *deletePhase({ payload }, { select, call, put }) {
      const response = yield call(deletePhase, payload);
      if(response){
        yield put({
          type: 'gameProject/findGameProject',
        });
      }
    },
    *finish({ payload, callback }, { select, call, put }) {
      const response = yield call(finish, payload);
      if(response){
        if(callback) callback()
      }
    },
    *findPhaseTeam({ payload }, { select, call, put }) {
      const response = yield call(findPhaseTeam, payload);
      yield put({
        type: 'changeState',
        payload: {
          mingdanList: response,
        },
      });
    },
  },

  reducers: {
    changeState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
